﻿using System;
using System.Drawing;
using DC2010.Objects;
using DC2010.Objects.Base;
using DC2010.Objects.Data;

namespace DC2010.Effects
{
    public class I_CreateItem_Effect : EffectLogic
    {
        public I_CreateItem_Effect(EffectData ed):base(ed)
        {
            ShortName = "Creates item";
            LongName = "This effect creates an item as parametrised.";
            Id = "I_CREATE_ITEM_EFFECT";
            EffectType = EffectType.Instant;
        }

        public override void Instant(BaseObject aInvoker, BaseObject aTarget)
        {
            if (aInvoker is CreatureData)
            {
                CreatureData c = (CreatureData) aInvoker;

                //check if hand is empty
                ItemData sLeft = c.L.Possession(CarryLocations.LeftHand);
                ItemData sRight = c.L.Possession(CarryLocations.RightHand);

                if ((sLeft != null)&&(sRight != null))
                {
                    Root.I.GameSystem.InGameLog(DateTime.Now.ToLongTimeString() + " - NEED AN EMPTY HAND TO PROCESS THIS SPELL.", Color.White);
                    return;
                }

                //get item id
                string pItemId = Data.Params.Find(A => A.Key == "ITEM_ID").Value;

                //create new item
                ItemData iNew = Root.I.ItemSystem.GetInfo(pItemId).CreateData();

                if (iNew==null) return;

                if (sLeft==null) c.Inventory.PutItemToPosition(CarryLocations.LeftHand, iNew.Id);
                if (sRight == null) c.Inventory.PutItemToPosition(CarryLocations.RightHand, iNew.Id);
            }

            base.Instant(aInvoker, aTarget);
        }
    }
}
